package be.novelfaces.webdriver.component.primefaces;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import be.novelfaces.webdriver.BaseComponent;

public class Tab<T extends TabContent> extends BaseComponent {
	
	private T content;

	public Tab(By compId, T content) {
		super(compId);
		this.content = content;
	}
	
	public boolean isSelected() {
		return getHeader().getAttribute("class").contains("ui-state-active");
	}

	private WebElement getHeader() {
		return getComponent().findElement(By.xpath("preceding-sibling::*[1]"));
	}
	
	public Tab<T> select() {
		getHeader().click();
		return this;
	}
	
	public WebElement findContentElement(By by) {
		return getComponent().findElement(by);
	}
	
	public T getContent() {
		return this.content;
	}
	
}
